home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / mudlib / master_skeleton.c < prev    next >
Text File  |  2001-04-03  |  43KB  |  1,158 lines

  1. /*  MASTER_NAME      (#define in config.h, or as commandline option)
  2. **  obj/master.c     (compat default)
  3. **  secure/master.c  (native default)
  4. **
  5. ** The master is the gateway between the gamedriver and the mudlib to perform
  6. ** actions with mudlib specific effects.
  7. ** Calls to the master by the gamedriver have an automatic catch() in effect.
  8. **
  9. ** This skeleton names all functions called by the gamedriver and gives
  10. ** suggestions on how to program then (a few by code).
  11. ** Functions which are specific to compat or native mode are tagged as such:
  12. **   '// !compat' means: only when not running in compat mode.
  13. **   '// native'  means: only when running in native mode.
  14. ** and similar for every other combination.
  15. **
  16. ** Note that the master is loaded first of all objects. Thus it is possible,
  17. ** you shouldn't inherit an other object (as most files expect the master
  18. ** to exist), nor is the compiler able to search include files
  19. ** (read: they must be specified with full path).
  20. */
  21.  
  22.  
  23. // A short reference to all functions...
  24. //---------------------------------------------------------------------------
  25. //     Initialisation
  26. //
  27. // void inaugurate_master (int arg)
  28. //   Perform mudlib specific setup of the master.
  29. //
  30. // string get_master_uid ()
  31. //   Return the string to be used as uid (and -euid) of a (re)loaded master.
  32. //
  33. // void flag (string arg)
  34. //   Evaluate an argument given as option '-f' to the driver.
  35. //
  36. // string *epilog (int eflag)
  37. //   Perform final actions before opening the game to players.
  38. //
  39. // void preload (string file)
  40. //   Preload a given object.
  41. //
  42. // void external_master_reload ()
  43. //   Called after a reload of the master on external request.
  44. //
  45. // void reactivate_destructed_master (int removed)
  46. //   Reactivate a formerly destructed master.
  47. //
  48. // string|string * get_simul_efun ()
  49. //   Load the simul_efun object(s) and return one or more paths of it.
  50. //
  51. //---------------------------------------------------------------------------
  52. //     Handling of player connections
  53. //
  54. // object connect ()
  55. //   Handle the request for a new connection.
  56. //
  57. // void disconnect (object obj)
  58. //   Handle the loss of an IP connection.
  59. //
  60. // void remove_player (object player)
  61. //   Remove a player object from the game.
  62. //
  63. // void stale_erq (closure callback)
  64. //   Notify the loss of the erq demon.
  65. //---------------------------------------------------------------------------
  66. //     Runtime Support
  67. //
  68. // object compile_object (string filename)
  69. //   Compile an virtual object.
  70. //
  71. // string get_wiz_name (string file)
  72. //   Return the author of a file.
  73. //
  74. // mixed include_file (string file, string compiled_file, int sys_include)
  75. //   Return the full pathname for an included file.
  76. //
  77. // mixed inherit_file (string file, string compiled_file)
  78. //   Return the full pathname for an inherited object.
  79. //
  80. // string object_name (object obj)
  81. //   Return a printable name for an object.
  82. //
  83. // mixed prepare_destruct (object obj)
  84. //   Prepare the destruction of the given object.
  85. //
  86. // void quota_demon (void)
  87. //   Handle quotas in times of memory shortage.
  88. //
  89. // void receive_udp (string host, string msg, int port)
  90. // void receive_imp (string host, string msg, int port) // deprecated
  91. //   Handle a received UDP message.
  92. //
  93. // void slow_shut_down (int minutes)
  94. //   Schedule a shutdown for the near future.
  95. //
  96. // void notify_shutdown ()
  97. //   Notify the master about an immediate shutdown.
  98. //
  99. //---------------------------------------------------------------------------
  100. //     Error Handling
  101. //
  102. // void dangling_lfun_closure ()
  103. //   Handle a dangling lfun-closure.
  104. //
  105. // void log_error (string file, string err, int warn)
  106. //   Announce a compiler-time error or warning.
  107. //
  108. // mixed heart_beat_error (object culprit, string err,
  109. //                         string prg, string curobj, int line)
  110. //   Announce an error in the heart_beat() function.
  111. //
  112. // void runtime_error (string err, string prg, string curobj, int line)
  113. //   Announce a runtime error.
  114. //
  115. //---------------------------------------------------------------------------
  116. //     Security and Permissions
  117. //
  118. // int privilege_violation (string op, mixed who, mixed arg, mixed arg2)
  119. //   Validate the execution of a privileged operation.
  120. //
  121. // int query_allow_shadow (object victim)
  122. //   Validate a shadowing.
  123. //
  124. // int valid_trace (string what, int|string arg)
  125. //   Check if the player may use tracing.
  126. //
  127. // int valid_exec (string name, object ob, object obfrom)
  128. //   Validate the rebinding of an IP connection by usage of efun exec().
  129. //
  130. // int valid_query_snoop (object obj)
  131. //   Validate if the snoopers of an object may be revealed by usage of the
  132. //   efun query_snoop().
  133. //
  134. // int valid_snoop (object snoopee, object snooper)
  135. //   Validate the start/stop of a snoop.
  136. //
  137. //---------------------------------------------------------------------------
  138. //     Userids and depending Security
  139. //
  140. // string get_bb_uid()
  141. //   Return the string to be used as backbone-uid.
  142. //
  143. // int valid_seteuid (object obj, string neweuid)
  144. //   Validate the change of an objects euid by efun seteuid().
  145. //
  146. // int|string valid_read  (string path, string euid, string fun, object caller)
  147. // int|string valid_write (string path, string euid, string fun, object caller)
  148. //   Validate a reading/writing file operation.
  149. //
  150. //---------------------------------------------------------------------------
  151. //     ed() Support
  152. //
  153. // string make_path_absolute (string str)
  154. //   Absolutize a relative filename given to the editor.
  155. //
  156. // int save_ed_setup (object who, int code)
  157. //   Save individual settings of ed for a wizard.
  158. //
  159. // int retrieve_ed_setup (object who)
  160. //   Retrieve individual settings of ed for a wizard.
  161. //
  162. // string get_ed_buffer_save_file_name (string file)
  163. //   Return a filename for the ed buffer to be saved into.
  164. //
  165. //---------------------------------------------------------------------------
  166. //     parse_command() Support  (!compat, SUPPLY_PARSE_COMMAND defined)
  167. //
  168. // string *parse_command_id_list ()
  169. //   Return generic singular ids.
  170. //
  171. // string *parse_command_plural_id_list ()
  172. //   Return generic plural ids.
  173. //
  174. // string *parse_command_adjectiv_id_list ()
  175. //   Return generic adjective ids.
  176. //
  177. // string *parse_command_prepos_list ()
  178. //   Return common prepositions.
  179. //
  180. // string parse_command_all_word()
  181. //   Return the one(!) 'all' word.
  182. //
  183. //---------------------------------------------------------------------------
  184.  
  185.  
  186. //===========================================================================
  187. //  Initialisation
  188. //
  189. // These functions are called after (re)loading the master to establish the
  190. // most basic operation parameters.
  191. //
  192. // The initialisation of LPMud on startup follows this schedule:
  193. //   - The gamedriver evaluates the commandline options and initializes
  194. //     itself.
  195. //   - The master is loaded, but since the driverhooks are not set yet,
  196. //     no standard initialisation lfun is called.
  197. //   - get_master_uid() is called. If the result is valid, it becomes the
  198. //     masters uid and euid.
  199. //   - inaugurate_master() is called.
  200. //   - flag() is called for each given '-f' commandline option.
  201. //   - get_simul_efun() is called.
  202. //   - the WIZLIST is read in.
  203. //   - epilog() is called. If it returns an array of strings, they are given
  204. //     one at a time as argument to preload().
  205. //     Traditionally, these strings are the filenames of the objects to
  206. //     preload, which preload() then does.
  207. //   - The gamedriver sets up the IP communication and enters the backend
  208. //     loop.
  209. //
  210. // If the master is reloaded during the game, this actions are taken:
  211. //   - The master is loaded, and its initialisation lfun is called according
  212. //     to the settings of the driverhooks (if set).
  213. //   - Any auto-include string and all driverhooks are cleared.
  214. //   - get_master_uid() is called. If the result is valid, it becomes the
  215. //     masters uid and euid.
  216. //   - inaugurate_master() is called.
  217. //
  218. // If the master was destructed, but couldn't be reloaded, the old
  219. // master object could be reactivated. In that case:
  220. //   - reactivate_destructed_master() is called.
  221. //   - inaugurate_master() is called.
  222. //===========================================================================
  223.  
  224. //---------------------------------------------------------------------------
  225. // Initialization of the master object.
  226. //
  227. // As the lfuns which are called to initialize objects after a load are
  228. // defined through driver hooks, and these hooks are cleared prior to
  229. // a master (re)load, the first function called is inaugurate_master().
  230. // Anyway it's not very sensible to do anything earlier as the master is
  231. // not recognized as such at that time, and so a number of (important) things
  232. // would not work.
  233. //
  234. // Which lfun is called during runtime to reset the master is also depending
  235. // on the driverhook settings. Arbitrary actions may be done on a reset.
  236.  
  237. //---------------------------------------------------------------------------
  238. void inaugurate_master (int arg)
  239.  
  240. // Perform mudlib specific setup of the master.
  241. //
  242. // Argument:
  243. //   arg: 0 if the mud just started.
  244. //        1 if the master is reactivated destructed one.
  245. //        2 if the master is a reactivated destructed one, which lost all
  246. //             variables.
  247. //        3 if the master was just reloaded.
  248. //
  249. // This function is called whenever the master becomes fully operational
  250. // after (re)loading (it is now recognized as _the_ master).
  251. // This doesn't imply that the game is up and running.
  252. //
  253. // This function has at least to set up the driverhooks to use. Also, any
  254. // mudwho or wizlist handling has to be initialized here.
  255. //
  256. // Besides that, do whatever you feel you need to do,
  257. // e.g. set_auto_include_string(), or give the master a decent euid.
  258.  
  259.  
  260. //---------------------------------------------------------------------------
  261. int|string get_master_uid ()
  262.  
  263. // Return the string to be used as uid (and -euid) of a (re)loaded master.
  264. // Under !native, the function may also return a non-zero number.
  265. // In that case, the uid is set to 0, as is the euid.
  266.  
  267.  
  268. //---------------------------------------------------------------------------
  269. void flag (string arg)
  270.  
  271. // Evaluate an argument given as option '-f' to the driver.
  272. //
  273. // Arguments:
  274. //   arg: The argument string from the option text '-f<arg>'.
  275. //        If several '-f' options are given, this function
  276. //        will be called sequentially with all given arguments.
  277. //
  278. // This function can be used to pass the master commands via arguments to
  279. // the driver. This is useful when building a new mudlib from scratch.
  280. // It is called only when the game is started.
  281. //
  282. // The code given implements these commands:
  283. //   '-fcall <ob> <fun> <arg>': call function <fun> in object <ob> with
  284. //                              argument <arg>.
  285. //   '-fshutdown': shutdown the game immediately.
  286. // Thus, starting the game as 'parse "-fcall foo bar Yow!" -fshutdown' would
  287. // first do foo->bar("Yow!") and then shutdown the game.
  288.  
  289. {
  290.   string obj, fun, rest;
  291.  
  292.   if (arg == "shutdown")
  293.   {
  294.     shutdown();
  295.     return;
  296.   }
  297.   if (sscanf(arg, "call %s %s %s", obj, fun, rest) >= 2)
  298.   {
  299.     write(obj+"->"+fun+"(\""+rest+"\") = ");
  300.     write(call_other(obj, fun, rest));
  301.     write("\n");
  302.     return;
  303.   }
  304.   write("master: Unknown flag "+arg+"\n");
  305. }
  306.  
  307.  
  308. //---------------------------------------------------------------------------
  309. string *epilog (int eflag)
  310.  
  311. // Perform final actions before opening the game to players.
  312. //
  313. // Arguments:
  314. //   eflag: This is the number of '-e' options given to the parser.
  315. //          Normally it is just 0 or 1.
  316. //
  317. // Result:
  318. //   An array of strings, which traditionally designate the objects to be
  319. //   preloaded with preload().
  320. //   Any other result is interpreted as 'no object to preload'.
  321. //   The resulting strings will be passed one at the time as
  322. //   arguments to preload().
  323.  
  324.  
  325. //---------------------------------------------------------------------------
  326. void preload (string file)
  327.  
  328. // Preload a given object.
  329. //
  330. // Arguments:
  331. //   file: The filename of the object to preload, as returned by epilog().
  332. //
  333. // It is task of the epilog()/preload() pair to ensure the validity of
  334. // the given strings (e.g. filtering out comments and blank lines).
  335. // For preload itself a 'load_object(file)' is sufficient, but it
  336. // should be guarded by a catch() to avoid premature blockings.
  337. // Also it is wise to change the master's euid from master_uid to something
  338. // less privileged for the time of the preload.
  339. //
  340. // You can of course do anything else with the passed strings - preloading
  341. // is just the traditional task.
  342.  
  343.  
  344. //---------------------------------------------------------------------------
  345. void external_master_reload ()
  346.  
  347. // Master was reloaded on external request by SIGUSR1.
  348. //
  349. // If the gamedriver destruct and reloads the master on external request
  350. // via SIGUSR1, it does this by a call to this function.
  351. // It will be called after inaugurate_master() of course.
  352. // If you plan to do additional magic here, you're welcome.
  353.  
  354.  
  355. //---------------------------------------------------------------------------
  356. void reactivate_destructed_master (int removed)
  357.  
  358. // Reactivate a formerly destructed master.
  359. //
  360. // Arguments:
  361. //   removed: True if the master was already on the list of destructed
  362. //            objects.
  363. //
  364. // This function is called in an formerly destructed master since a new master
  365. // couldn't be loaded.
  366. // This function has to reinitialize all variables at least to continue
  367. // operation.
  368.  
  369.  
  370. //---------------------------------------------------------------------------
  371. string|string * get_simul_efun ()
  372.  
  373. // Load the simul_efun object(s) and return one or more paths of it.
  374. //
  375. // Result:
  376. //   Either a single string with the file_name() of the simul_efun object,
  377. //   or an array of strings which has to start with that file_name().
  378. //   Return 0 if this feature isn't wanted.
  379. //
  380. // Note that the object(s) must be loaded by this function!
  381. //
  382. // When you return an array of strings, the first string is taken as path
  383. // to the simul_efun object, and all other paths are used for backup
  384. // simul_efun objects to call simul_efuns that are not present in the
  385. // main simul_efun object. This allows to remove simul_efuns at runtime
  386. // without getting errors from old compiled programs that still use the
  387. // obsolete simul_efuns. A side use of this mechanism is to provide
  388. // a 'spare' simul_efun object in case the normal one fails to load.
  389. //
  390. // If the game depends on the simul_efun object, and none could be loaded,
  391. // an immediate shutdown should occur.
  392.  
  393.  
  394. //===========================================================================
  395. //  Handling of player connections
  396. //
  397. // See also valid_exec().
  398. //===========================================================================
  399.  
  400. //---------------------------------------------------------------------------
  401. object connect ()
  402.  
  403. // Handle the request for a new connection.
  404. //
  405. // Result:
  406. //   An login object the requested connection should be bound to.
  407. //
  408. // Note that the connection is not bound yet!
  409. //
  410. // The gamedriver will call the lfun 'logon()' in the login object after
  411. // binding the connection to it. That lfun has to return !=0 to succeed.
  412.  
  413.  
  414. //---------------------------------------------------------------------------
  415. void disconnect (object obj)
  416.  
  417. // Handle the loss of an IP connection.
  418. //
  419. // Argument:
  420. //   obj: The (formerly) interactive object (player).
  421. //
  422. // This called by the gamedriver to handle the removal of an IP connection,
  423. // either because the connection is already lost ('netdeath') or due to
  424. // calls to exec() or remove_interactive().
  425. // The connection will be unbound upon return from this call.
  426.  
  427.  
  428. //---------------------------------------------------------------------------
  429. void remove_player (object player)
  430.  
  431. // Remove a player object from the game.
  432. //
  433. // Argument:
  434. //   player: The player object to be removed.
  435. //
  436. // This function is called by the gamedriver to expell remaining players
  437. // from the game on shutdown in a polite way.
  438. // If this functions fails to quit/destruct the player, it will be
  439. // destructed the hard way by the gamedriver.
  440. //
  441. // Note: This function must not cause runtime errors.
  442.  
  443.  
  444. //---------------------------------------------------------------------------
  445. void stale_erq (closure callback)
  446.  
  447. // Notify the loss of the erq demon.
  448. //
  449. // Argument:
  450. //   callback: the callback closure set for an erq request.
  451. //
  452. // If the erq connection dies prematurely, the driver will call this lfun for
  453. // every pending request with set callback. This function should notify the
  454. // originating object that the answer will never arrive.
  455.  
  456.  
  457. //===========================================================================
  458. //  Runtime Support
  459. //
  460. // Various functions used to implement advanced runtime features.
  461. //===========================================================================
  462.  
  463. //---------------------------------------------------------------------------
  464. object compile_object (string filename)
  465.  
  466. // Compile an virtual object.
  467. //
  468. // Arguments:
  469. //   previous_object(): The object requesting the virtual object.
  470. //   filename         : The requested filename for the virtual object.
  471. //
  472. // Result:
  473. //   The object to serve as the requested virtual object, or 0.
  474. //
  475. // This function is called if the compiler can't find the filename for an
  476. // object to compile. The master has now the opportunity to return an other
  477. // which will then serve as if it was compiled from <filename>.
  478. // If the master returns 0, the usual 'Could not load'-error will occur.
  479.  
  480.  
  481. //---------------------------------------------------------------------------
  482. mixed include_file (string file, string compiled_file, int sys_include)
  483.  
  484. // Generate the pathname of an included file.
  485. //
  486. // Arguments:
  487. //   previous_object(): The object causing the compile.
  488. //   file             : The name given in the #include directive.
  489. //   compiled_file    : The object file which is just compiled
  490. //                      (compat: name without leading "/").
  491. //   sys_include      : TRUE for #include <> directives.
  492. //
  493. // Result:
  494. //   0:      use the normal include filename generation (""-includes are used
  495. //           as they are, <>-includes are handled according to H_INCLUDE_DIRS).
  496. //   <path>: the full absolute pathname of the file to include without
  497. //           parentdir parts ("/../"). Leading slashes ("/") may be omitted.
  498. //   else:   The include directive is not legal.
  499.  
  500. //---------------------------------------------------------------------------
  501. mixed inherit_file (string file, string compiled_file)
  502.  
  503. // Generate the pathname of an inherited file.
  504. //
  505. // Arguments:
  506. //   previous_object(): The object causing the compile.
  507. //   file             : The name given in the inherit directive.
  508. //   compiled_file    : The object file which is just compiled
  509. //                      (compat: name without leading "/").
  510. //
  511. // Result:
  512. //   0:      use the filename as it is.
  513. //   <path>: the full absolute pathname of the file to inherit without
  514. //           parentdir parts ("/../"). Leading slashes ("/") are ignored.
  515. //   else:   The include directive is not legal.
  516.  
  517. //---------------------------------------------------------------------------
  518. string get_wiz_name (string file)
  519.  
  520. // Return the author of a file.
  521. //
  522. // Arguments:
  523. //   file: The name of the file in question.
  524. //
  525. // Result:
  526. //   The name of the file's author (or 0 if there is none).
  527. //
  528. // This function is called for maintenance of the wiz-list, to score errors
  529. // to the right wizard.
  530.  
  531.  
  532. //---------------------------------------------------------------------------
  533. string printf_obj_name (object obj)
  534.  
  535. // Return a printable name for an object.
  536. //
  537. // Arguments:
  538. //   obj: The object which name is of interest.
  539. //
  540. // Result:
  541. //   A string with the objects name, or 0.
  542. //
  543. // This function is called by sprintf() to print a meaningful name
  544. // in addition to the normal object_name().
  545. // If this functions returns a string, the object will be printed
  546. // as "<obj_name> (<printf_obj_name>)".
  547.  
  548.  
  549. //---------------------------------------------------------------------------
  550. mixed prepare_destruct (object obj)
  551.  
  552. // Prepare the destruction of the given object.
  553. //
  554. // Argument:
  555. //   obj : The object to destruct.
  556. //
  557. // Result:
  558. //   Return 0 if the object is ready for destruction, any other value
  559. //   will abort the attempt.
  560. //   If a string is returned, an error with the string as message will
  561. //   be issued.
  562. //
  563. // The gamedriver calls this function whenever an object shall be destructed.
  564. // It expects, that this function cleans the inventory of the object, or
  565. // the destruct will fail.
  566. // Furthermore, the function could notify the former inventory objects that
  567. // their holder is under destruction (useful to move players out of rooms which
  568. // are updated); and it could announce mudwide the destruction(quitting) of
  569. // players.
  570.  
  571.  
  572. //---------------------------------------------------------------------------
  573. void quota_demon (void)
  574.  
  575. // Handle quotas in times of memory shortage.
  576. //
  577. // This function is called during the final phase of a garbage collection if
  578. // the reserved user area couldn't be reallocated. This function (or a called
  579. // demon) has now the opportunity to remove some (still active) objects from
  580. // the game. If this does not free enough memory to reallocate the user
  581. // reserve, slow_shut_down() will be called to start Armageddon.
  582. //
  583. // Note: Up to now, the wizlist lacks various informations needed to detect
  584. //   the memory-hungriest wizards.
  585.  
  586.  
  587. //---------------------------------------------------------------------------
  588. void receive_udp (string host, string msg, int port)
  589. void receive_imp (string host, string msg, int port) // deprecated
  590.  
  591. // Handle a received UDP message.
  592. //
  593. // Arguments:
  594. //   host: Name of the host the message comes from.
  595. //   msg : The received message.
  596. //   port: the port number from which the message was sent.
  597. //
  598. // This function is called for every message received on the UDP port.
  599. //
  600. // The driver first calls receive_udp(). If that method doesn't exist
  601. // and if the driver is compiled with USE_DEPRECATED, it will then
  602. // call receive_imp().
  603.  
  604.  
  605. //---------------------------------------------------------------------------
  606. void slow_shut_down (int minutes)
  607.  
  608. // Schedule a shutdown for the near future.
  609. //
  610. // Argument:
  611. //   minutes: The desired time in minutes till the shutdown:
  612. //             6, if just the user reserve has been put into use;
  613. //             1, if the (smaller) system or even the master reserve
  614. //                has been put into use as well.
  615. //
  616. // The gamedriver calls this function when it runs low on memory.
  617. // At this time, it has freed its reserve, but since it won't last long,
  618. // the games needs to be shut down. Don't take the 'minutes' as granted
  619. // remaining uptime, just deduce the urgency of the shutdown from it.
  620. // The delay is to give the players the opportunity to finish quests,
  621. // sell their stuff, etc.
  622. // It is possible that the driver may reallocate some memory after the
  623. // function has been called, and then run again into a low memory situation,
  624. // calling this function again.
  625. //
  626. // For example: this function might load an 'Armageddon' object and tells
  627. // it what to do. It is the Armageddon object then which performs
  628. // the shutdown.
  629. //
  630. // Technical:
  631. //   The memory handling of the gamedriver includes three reserved areas:
  632. //   user, system and master. All three are there to insure that the game
  633. //   shuts down gracefully when the memory runs out: the user area to give
  634. //   the players time to quit normally, the others to enable emergency-logouts
  635. //   when the user reserve is used up as well.
  636. //   The areas are allocated at start of the gamedriver, and released when
  637. //   no more memory could be obtained from the host. In such a case, one
  638. //   of the remaining areas is freed (so the game can continue a short
  639. //   while) and a garbagecollection is initiated.
  640. //   If the garbagecollection recycles enough memory (either true garbage
  641. //   or by the aid of the quota_demon) to reallocate the areas, all is
  642. //   fine, else the game is shut down by a call to this function.
  643.  
  644. //---------------------------------------------------------------------------
  645. void notify_shutdown (void)
  646.  
  647. // Notify the master about an immediate shutdown.
  648. //
  649. // If the gamedriver shuts down, this is the last function called before
  650. // the mud shuts down the udp connections and the accepting socket for new
  651. // players.
  652. // The function has the opportunity to perform any cleanup operation, like
  653. // informing the mudwho server that the mud is down. This can not be done
  654. // when remove_player() is called because the udp connectivity is already
  655. // gone then.
  656.  
  657.  
  658. //===========================================================================
  659. //  Error Handling
  660. //
  661. //===========================================================================
  662.  
  663. //---------------------------------------------------------------------------
  664. void dangling_lfun_closure ()
  665.  
  666. // Handle a dangling lfun-closure.
  667. //
  668. // This is called when the gamedriver executes a closure using a vanished lfun.
  669. // A proper handling is to raise a runtime error.
  670. //
  671. // Technical:
  672. //   Upon replacing programs (see efun replace_program()), any existing
  673. //   lambda closures of the object are adjusted to the new environment.
  674. //   If a closure uses a lfun which vanished in the replacement process,
  675. //   the reference to this lfun is replaced by a reference to this function.
  676. //   The error will then occur when the execution of the adjusted lambda
  677. //   reaches the point of the lfun reference.
  678. //   There are two reasons for the delayed handling. First is that the
  679. //   program replacement and with it the closure adjustment happens at
  680. //   the end of a backend cycle, outside of any execution thread: noone
  681. //   would see the error at this time.
  682. //   Second, smart closures might know/recognize the program replacement
  683. //   and skip the call to the vanished lfun.
  684.  
  685. {
  686.   raise_error("dangling lfun closure\n");
  687. }
  688.  
  689. //---------------------------------------------------------------------------
  690. void log_error (string file, string err, int warn)
  691.  
  692. // Announce a compiler-time error or warning.
  693. //
  694. // Arguments:
  695. //   file: The name of file containing the error/warning (it needn't be
  696. //         an object file!).
  697. //   err : The error/warning message.
  698. //   warn: non-zero if this is a warning, zero if it is an error.
  699. //
  700. // Whenever the LPC compiler detects an error or wants to issue a warning,
  701. // this function is called.
  702. // It should at least log the message in a file, and also announce it
  703. // to the active player if it is an wizard.
  704.  
  705.  
  706. //---------------------------------------------------------------------------
  707. mixed heart_beat_error (object culprit, string err,
  708.                         string prg, string curobj, int line)
  709.  
  710. // Announce an error in the heart_beat() function.
  711. //
  712. // Arguments:
  713. //   culprit: The object which lost the heart_beat.
  714. //   err    : The error message.
  715. //   prg    : The executed program (might be 0).
  716. //   curobj : The object causing the error (might be 0).
  717. //   line   : The line number where the error occured (might be 0).
  718. //
  719. // Result:
  720. //   Return anything != 0 to restart the heart_beat in culprit.
  721. //
  722. // This function has to announce an error in the heart_beat() function
  723. // of culprit.
  724. // At time of call, the heart_beat has been turned off.
  725. // A player should at least get a "You have no heartbeat!" message, a more
  726. // advanced handling would destruct the offending object and allow the
  727. // heartbeat to restart.
  728. //
  729. // Note that <prg> denotes the program actually executed (which might be
  730. // inherited one) whereas <curobj> is just the offending object.
  731.  
  732.  
  733. //---------------------------------------------------------------------------
  734. void runtime_error (string err, string prg, string curobj, int line
  735.                    , mixed culprit)
  736.  
  737. // Announce a runtime error.
  738. //
  739. // Arguments:
  740. //   err    : The error message.
  741. //   prg    : The executed program.
  742. //   curobj : The object causing the error.
  743. //   line   : The line number where the error occured.
  744. //   culprit: -1 for runtime errors; the object holding the heart_beat()
  745. //            function for heartbeat errors.
  746. //
  747. // This function has to announce a runtime error to the active user,
  748. // resp. handle a runtime error which occured during the execution of
  749. // heart_beat() of <culprit>.
  750. //
  751. // For a normal runtime error, if the active user is a wizard, it might
  752. // give him the full error message together with the source line; if the
  753. // user is a is a player, it should issue a decent message ("Your sensitive
  754. // mind notices a wrongness in the fabric of space") and could also announce
  755. // the error to the wizards online.
  756. //
  757. // If the error is a heartbeat error, the heartbeat for the offending
  758. // <culprit> has been turned off. The function itself shouldn't do much, since
  759. // the lfun heart_beat_error() will be called right after this one.
  760. //
  761. // Note that <prg> denotes the program actually executed (which might be
  762. // inherited) whereas <curobj> is just the offending object for which the
  763. // program was executed.
  764.  
  765.  
  766. //===========================================================================
  767. //  Security and Permissions
  768. //
  769. // Most of these functions guard critical efuns. A good approach to deal
  770. // with them is to redefine the efuns by simul_efuns (which can then avoid
  771. // trouble prematurely) and give root objects only the permission to
  772. // execute the real efuns.
  773. //
  774. // See also creator_file(), valid_read() and valid_write().
  775. //===========================================================================
  776.  
  777. //---------------------------------------------------------------------------
  778. int privilege_violation (string op, mixed who, mixed arg, mixed arg2)
  779.  
  780. // Validate the execution of a privileged operation.
  781. //
  782. // Arguments:
  783. //   op   : the requestion operation (see below)
  784. //   who  : the object requesting the operation (filename or object pointer)
  785. //   arg  : additional argument, depending on <op>.
  786. //   arg2 : additional argument, depending on <op>.
  787. //
  788. // Result:
  789. //     >0: The caller is allowed for this operation.
  790. //      0: The caller was probably misleaded; try to fix the error
  791. //   else: A real privilege violation; handle it as error.
  792. //
  793. // Privileged operations are:
  794. //   attach_erq_demon  : Attach the erq demon to object <arg> with flag <arg2>.
  795. //   bind_lambda       : Bind a lambda-closure to object <arg>.
  796. //   call_out_info     : Return an array with all call_out informations.
  797. //   erq               : A the request <arg4> is to be send to the
  798. //                       erq-demon by the object <who>.
  799. //   execute_command   : Execute command string <arg2> for the object <arg>.
  800. //   input_to          : Object <who> issues an 'ignore-bang'-input_to() for
  801. //                       commandgiver <arg3>; the exakt flags are <arg4>.
  802. //   nomask simul_efun : Attempt to get an efun <arg> via efun:: when it
  803. //                       is shadowed by a 'nomask'-type simul_efun.
  804. //   rename_object     : The current object <who> renames object <arg>
  805. //                       to name <arg2>.
  806. //   send_imp          : Send UDP-data to host arg3 (deprecated).
  807. //   send_udp          : Send UDP-data to host <arg>.
  808. //   set_auto_include_string : Set the string automatically included by
  809. //                       the compiler.
  810. //   get_extra_wizinfo : Get the additional wiz-list info for wizard <arg>.
  811. //   set_extra_wizinfo : Set the additional wiz-list info for wizard <arg>.
  812. //   set_extra_wizinfo_size : Set the size of the additional wizard info
  813. //                       in the wiz-list to <arg>.
  814. //   set_driver_hook   : Set hook <arg> to <arg2>.
  815. //   limited:          : Execute <arg> with reduced/changed limits.
  816. //   set_limits        : Set limits to <arg>.
  817. //   set_this_object   : Set this_object() to <arg>.
  818. //   shadow_add_action : Add an action to function <arg> from a shadow.
  819. //   symbol_variable   : Attempt to create symbol of a hidden variable
  820. //                       of object <arg> with with index <arg2> in the
  821. //                       objects variable table.
  822. //   wizlist_info      : Return an array with all wiz-list information.
  823. //
  824. // call_out_info can return the arguments to functions and lambda closures
  825. // to be called by call_out(); you should consider that read access to
  826. // closures, mappings and pointers means write access and/or other privileges.
  827. // wizlist_info() will return an array which holds, among others, the extra
  828. // wizlist field. While a toplevel array, if found, will be copied, this does
  829. // not apply to nested arrays or to any mappings. You might also have some
  830. // sensitive closures there.
  831. // send_udp() should be watched as it could be abused to mess up the IMP.
  832. // The xxx_extra_wizinfo operations are necessary for a proper wizlist and
  833. // should therefore be restricted to admins.
  834. // All other operations are potential sources for direct security breaches -
  835. // any use of them should be scrutinized closely.
  836.  
  837. //---------------------------------------------------------------------------
  838. int query_allow_shadow (object victim)
  839.  
  840. // Validate a shadowing.
  841. //
  842. // Arguments:
  843. //   previous_object(): the wannabe shadow
  844. //   victim           : the object to be shadowed.
  845. //
  846. // Result:
  847. //   Return 0 to disallow the shadowing, any other value to allow it.
  848. //   Destructing the shadow or the victim is another way of disallowing.
  849. //
  850. // The function should deny shadowing on all root objects, else it might
  851. // query the victim for clearance.
  852.  
  853.  
  854. //---------------------------------------------------------------------------
  855. int valid_trace (string what, int|string arg)
  856.  
  857. // Check if the player is allowed to use tracing.
  858. //
  859. // Argument:
  860. //   what: The actual action (see below).
  861. //   arg:  The argument given to the traceing efun.
  862. //
  863. // Result:
  864. //   Return 0 to disallow, any other value to allow it.
  865. //
  866. // Actions asked for so far are:
  867. //   "trace":       Is the user allowed to use tracing?
  868. //                  <arg> is the tracelevel argument given.
  869. //   "traceprefix": Is the user allowed to set a traceprefix?
  870. //                  <arg> is the prefix given.
  871.  
  872. //---------------------------------------------------------------------------
  873. int valid_exec (string name, object ob, object obfrom)
  874.  
  875. // Validate the rebinding of an IP connection by usage of efun exec().
  876. //
  877. // Arguments:
  878. //    name  : The name of the _program_ attempting to rebind the connection.
  879. //            This is not the file_name() of the object, and has no leading
  880. //            slash.
  881. //    ob    : The object to receive the connection.
  882. //    obfrom: The object giving the connection away.
  883. //
  884. // Result:
  885. //   Return a non-zero number to allow the action,
  886. //   any other value to disallow it.
  887.  
  888.  
  889. //---------------------------------------------------------------------------
  890. int valid_query_snoop (object obj)
  891.  
  892. // Validate if the snoopers of an object may be revealed by usage of the
  893. // efun query_snoop().
  894. //
  895. // Arguments:
  896. //   previous_object(): the asking object.
  897. //   obj              : the object which snoopers are to be revealed.
  898. //
  899. // Result:
  900. //   Return a non-zero number to allow the action,
  901. //   any other value to disallow it.
  902.  
  903.  
  904. //---------------------------------------------------------------------------
  905. int valid_snoop (object snoopee, object snooper)
  906.  
  907. // Validate the start/stop of a snoop.
  908. //
  909. // Arguments:
  910. //   snoopee: The victim of the snoop.
  911. //   snooper: The wannabe snooper, or 0 when stopping a snoop.
  912. //
  913. // Result:
  914. //   Return a non-zero number to allow the action,
  915. //   any other value to disallow it.
  916.  
  917.  
  918. //===========================================================================
  919. //  Userids and depending Security
  920. //
  921. // For each object in the mud exists a string attribute which determines the
  922. // objects rights in security-sensitive matters. In compat muds this attribute
  923. // is called the "creator" of the object, in !compat muds the object's "userid"
  924. // ("uid" for short).
  925. //
  926. // "Effective Userids" are an extension of this system, to allow the easier
  927. // implementation of mudlib security by diffentiating between an objects
  928. // theoretical permissions (uid) and its current permissions (euid) (some
  929. // experts think that this attempt has failed (Heya Macbeth!)).
  930. //
  931. // The driver mainly implements the setting/querying of the (e)uids -- it is
  932. // task of the mudlib to give out the right (e)uid to the right object, and
  933. // to check them where necessary.
  934. //
  935. // If the driver is set to use 'strict euids', the loading and cloning
  936. // of objects requires the initiating object to have a non-zero euid.
  937. //
  938. // The main use for (e)uids is for determination of file access rights, but
  939. // you can of course use the (e)uids for other identification purposes as well.
  940. //===========================================================================
  941.  
  942. //---------------------------------------------------------------------------
  943. string get_bb_uid()
  944.  
  945. // Return the string (or 0) to be used as backbone-euid.
  946. // It is just used by process_string() only if no this_object() is present.
  947. // If strict-euids, the function must exist and return a string.
  948.  
  949. //---------------------------------------------------------------------------
  950. int valid_seteuid (object obj, string neweuid)
  951.  
  952. // Validate the change of an objects euid by efun seteuid().
  953. //
  954. // Arguments:
  955. //   obj    : The object requesting the new euid.
  956. //   neweuid: The new euid requested.
  957. //
  958. // Result:
  959. //   Return 1 to allow the change, any other value to disallow it.
  960.  
  961.  
  962. //---------------------------------------------------------------------------
  963. mixed valid_read  (string path, string euid, string fun, object caller)
  964. mixed valid_write (string path, string euid, string fun, object caller)
  965.  
  966. // Validate a reading/writing file operation.
  967. //
  968. // Arguments:
  969. //   path   : The (possibly partial) filename given to the operation.
  970. //   euid   : the euid of the caller (might be 0).
  971. //   fun    : The name of the operation requested (see below).
  972. //   caller : The calling object.
  973. //
  974. // Result:
  975. //   The full pathname of the file to operate on, or 0 if the action is not
  976. //   allowed.
  977. //   You can also return 1 to indicate that the path can be used unchanged.
  978. //
  979. // The path finally to be used must not contain spaces or '..'s .
  980. //
  981. // These are the central functions establishing the various file access
  982. // rights.
  983. //
  984. // Note that this function is called in compat mode as well!
  985. // If you need to be compatible with the old 2.4.5-mudlib, redirect these
  986. // calls to the valid_read/valid_write in the player object.
  987. //
  988. // valid_read() is called for these operations:
  989. //   copy_file       (for the source file)
  990. //   ed_start        (when reading a file)
  991. //   file_size
  992. //   get_dir
  993. //   print_file
  994. //   read_bytes
  995. //   read_file
  996. //   restore_object
  997. //   tail
  998. //
  999. // For restore_object(), the <path> passed is the filename as given
  1000. // in the efun call.
  1001. //
  1002. //
  1003. // valid_write() is called for these operations:
  1004. //   copy_file    (for the target file resp. directory name)
  1005. //   ed_start     (when writing a file)
  1006. //   rename_from  (for each the old name of a rename())
  1007. //   rename_to    (for the new name of a rename())
  1008. //   mkdir
  1009. //   objdump
  1010. //   opcdump
  1011. //   save_object
  1012. //   remove_file
  1013. //   rmdir
  1014. //   write_bytes
  1015. //   write_file
  1016. //
  1017. // For save_object(), the <path> passed is the filename as given
  1018. // in the efun call. If for this efun a filename ending in ".c" is
  1019. // returned, the ".c" will be stripped from the filename.
  1020.  
  1021.  
  1022.  
  1023. //===========================================================================
  1024. //  ed() Support
  1025. //
  1026. //===========================================================================
  1027.  
  1028. //---------------------------------------------------------------------------
  1029. string make_path_absolute (string str)
  1030.  
  1031. // Absolutize a relative filename given to the editor.
  1032. //
  1033. // Argument:
  1034. //   str : The relative filename (without leading slash).
  1035. //
  1036. // Result:
  1037. //   The full pathname of the file to use.
  1038. //   Any non-string result will act as 'bad file name'.
  1039.  
  1040.  
  1041. //---------------------------------------------------------------------------
  1042. int save_ed_setup (object who, int code)
  1043.  
  1044. // Save individual settings of ed for a wizard.
  1045. //
  1046. // Arguments:
  1047. //   who : The wizard using the editor.
  1048. //   code: The encoded options to be saved.
  1049. //
  1050. // Result:
  1051. //   Return 0 on failure, any other value for success.
  1052. //
  1053. // This function has to save the given integer into a safe place in the
  1054. // realm of the given wizard, either a file, or in the wizard itself.
  1055. //
  1056. // Be aware of possible security breaches: under !compat, a write_file()
  1057. // should be surrounded by a temporary setting of the masters euid to
  1058. // that of the wizard.
  1059.  
  1060.  
  1061. //---------------------------------------------------------------------------
  1062. int retrieve_ed_setup (object who)
  1063.  
  1064. // Retrieve individual settings of ed for a wizard.
  1065. //
  1066. // Arguments:
  1067. //   who : The wizard using the editor.
  1068. //
  1069. // Result:
  1070. //   The encoded options retrieved (0 if there are none).
  1071.  
  1072.  
  1073. //---------------------------------------------------------------------------
  1074. string get_ed_buffer_save_file_name (string file)
  1075.  
  1076. // Return a filename for the ed buffer to be saved into.
  1077. //
  1078. // Arguments:
  1079. //   this_player(): The wizard using the editor.
  1080. //   file         : The name of the file currently in the buffer.
  1081. //
  1082. // Result:
  1083. //   The name of the file to save the buffer into, or 0.
  1084. //
  1085. // This function is called whenever a wizard is destructed/goes netdeath
  1086. // while editing. Using this function, his editing is not done in vain.
  1087.  
  1088.  
  1089. //===========================================================================
  1090. //  parse_command() Support  (!compat, SUPPLY_PARSE_COMMAND defined)
  1091. //
  1092. // LPMud has a builtin support for parsing complex commands.
  1093. // It does this by requestion several types of ids from the objects.
  1094. // The same queried functions are also in the master to provide decent
  1095. // defaults, especially for generic ids like 'all the blue ones'.
  1096. //
  1097. // Each of the functions has to return an array of strings (with the exception
  1098. // of parse_command_all_word), each string being one of the ids for that type
  1099. // of id.
  1100. //
  1101. // The whole parsing has a preference for the english language, so the
  1102. // the code for parsing english constructs is given as well.
  1103. //===========================================================================
  1104.  
  1105. //---------------------------------------------------------------------------
  1106. string *parse_command_id_list ()
  1107.  
  1108. // Return generic singular ids.
  1109.  
  1110. {
  1111.   return ({ "one", "thing" });
  1112. }
  1113.  
  1114.  
  1115. //---------------------------------------------------------------------------
  1116. string *parse_command_plural_id_list ()
  1117.  
  1118. // Return generic plural ids.
  1119.  
  1120. {
  1121.   return ({ "ones", "things", "them" });
  1122. }
  1123.  
  1124.  
  1125. //---------------------------------------------------------------------------
  1126. string *parse_command_adjectiv_id_list ()
  1127.  
  1128. // Return generic adjective ids.
  1129. // If there are none (like here), return some junk which is likely never
  1130. // typed.
  1131.  
  1132. {
  1133.   return ({ "iffish" });
  1134. }
  1135.  
  1136.  
  1137. //---------------------------------------------------------------------------
  1138. string *parse_command_prepos_list ()
  1139.  
  1140. // Return common prepositions.
  1141.  
  1142. {
  1143.     return ({ "in", "on", "under", "behind", "beside" });
  1144. }
  1145.  
  1146.  
  1147. //---------------------------------------------------------------------------
  1148. string parse_command_all_word()
  1149.  
  1150. // Return the one(!) 'all' word.
  1151.  
  1152. {
  1153.   return "all";
  1154. }
  1155.  
  1156.  
  1157. /****************************************************************************/
  1158.